package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.CtfExperimentalEnvironment;
import com.ruoyi.experiment.service.ICtfExperimentalEnvironmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CTF实验环境Controller
 * 
 * @author 邓鑫
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/experiment/ctfenvironment")
public class CtfExperimentalEnvironmentController extends BaseController
{
    @Autowired
    private ICtfExperimentalEnvironmentService ctfExperimentalEnvironmentService;

    /**
     * 查询CTF实验环境列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CtfExperimentalEnvironment ctfExperimentalEnvironment)
    {
        startPage();
        List<CtfExperimentalEnvironment> list = ctfExperimentalEnvironmentService.selectCtfExperimentalEnvironmentList(ctfExperimentalEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出CTF实验环境列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:export')")
    @Log(title = "CTF实验环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtfExperimentalEnvironment ctfExperimentalEnvironment)
    {
        List<CtfExperimentalEnvironment> list = ctfExperimentalEnvironmentService.selectCtfExperimentalEnvironmentList(ctfExperimentalEnvironment);
        ExcelUtil<CtfExperimentalEnvironment> util = new ExcelUtil<CtfExperimentalEnvironment>(CtfExperimentalEnvironment.class);
        util.exportExcel(response, list, "CTF实验环境数据");
    }

    /**
     * 获取CTF实验环境详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:query')")
    @GetMapping(value = "/{ctfEnvironmentId}")
    public AjaxResult getInfo(@PathVariable("ctfEnvironmentId") Long ctfEnvironmentId)
    {
        return success(ctfExperimentalEnvironmentService.selectCtfExperimentalEnvironmentByCtfEnvironmentId(ctfEnvironmentId));
    }

    /**
     * 新增CTF实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:add')")
    @Log(title = "CTF实验环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtfExperimentalEnvironment ctfExperimentalEnvironment)
    {
        return toAjax(ctfExperimentalEnvironmentService.insertCtfExperimentalEnvironment(ctfExperimentalEnvironment));
    }

    /**
     * 修改CTF实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:edit')")
    @Log(title = "CTF实验环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtfExperimentalEnvironment ctfExperimentalEnvironment)
    {
        return toAjax(ctfExperimentalEnvironmentService.updateCtfExperimentalEnvironment(ctfExperimentalEnvironment));
    }

    /**
     * 删除CTF实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:remove')")
    @Log(title = "CTF实验环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ctfEnvironmentIds}")
    public AjaxResult remove(@PathVariable Long[] ctfEnvironmentIds)
    {
        return toAjax(ctfExperimentalEnvironmentService.deleteCtfExperimentalEnvironmentByCtfEnvironmentIds(ctfEnvironmentIds));
    }

    /**
     * 生成环境实例
     */
    @PreAuthorize("@ss.hasPermi('experiment:ctfenvironment:addExample')")
    @PostMapping("/addExample/{ctfEnvironmentId}")
    public AjaxResult addExample(@PathVariable Long ctfEnvironmentId)
    {
        ctfExperimentalEnvironmentService.addExample(ctfEnvironmentId);
        return new AjaxResult(200,"生成实例成功");
    }
}
